#include"Main.h"
#include"OLED.h"
///////////////////////K60freescale//////////////////////////////////////
void main (void);
void main (void)
{    
     DriveInit();
     bell_open;
     LED1H;LED2H;LED3H;
     delay(3000);
     bell_close;
     
     LED1L;LED2L;LED3L;
     Flash_Parameter_read();
     getchuzhi(); 
     pit_init();
     
     while(1)
   {        
       Key_Parameter_Set();
       delay(100); 
    //   scope( black_line,rignt_angle_flag, black_line_2,Direction_E0); 
     //   scope( CCD_AD[(int) (CCD_MIDLine-13)],CCD_AD[(int) (CCD_MIDLine+13)], CarSpeed,Direction_E0*10); 
        scope(Direction_Error0*100,Direction_E0*100,CarSpeed,SpeedControlIntegral*100);      
      //  scope(a2,(SpeedControlIntegral*100), (CarSpeed),(SpeedControlOutNew*100));     
       //  scope((int)(100*fD),(fP*100), (CarSpeed),(fI*100));     
    // scope((int)(Direction_Error0*10000),(0) , 0, (0));         
    //   scope((int)(CAR_SPEEDGIVE*50),(int)(CarSpeed*50) ,(int)speedleft, (int)speedright);       
   // scope( (int)(CCD_leftline),(int)(CCD_rightline),(int)(CCD_MIDLine),(int)0);
   //    scope( (int)(CarAngle*10),(int)(GravityAngle*10),(int)(CV_GYROx),V_GYROx);    
  LCD_Show_Number (0,0,(int)(10000*ANGLE_P));         LCD_Show_Number (8,0, (int)(10000*SPEED_CONTROL_P));    LCD_Show_Number (16,0,(int)( Direction_P*10000));
                                                      LCD_Show_Number (8,1, (int)(10000*SPEED_CONTROL_I));    
  LCD_Show_Number (0,2,(int)(10000*ANGLE_D));         LCD_Show_Number (8,2, (int)(10000*SPEED_CONTROL_D));    LCD_Show_Number (16,2,(int)( Direction_D*10000));
  LCD_Show_Number (0,3,(int)(rignt_angle_flag*10));   LCD_Show_Number (8,3, (int)(black_line*10));             LCD_Show_Number (16,3, (int)(rignt_angle_count*10));
                                                      LCD_Show_Number (8,4,   VCC*1000);                      LCD_Show_Number (16,4,(int)(CCD_Threshold));
  LCD_Show_Number (0,5, (int) leftline);              LCD_Show_Number (8,5,  (int)   rightline);              LCD_Show_Number (16,5,(int) CCD_MIDLine);
  LCD_Show_Number (0,6, (int) CCD_leftline);          LCD_Show_Number (8,6,  (int)   CCD_rightline);          LCD_Show_Number (16,6 ,(int) MIDLine_AD_last);
  LCD_Show_Number (0,7, (int) CCD_AD[CCD_leftline]);  LCD_Show_Number (8,7,  (int)   CCD_AD[CCD_rightline]);  LCD_Show_Number (16,7, CCD_AD[(int) CCD_MIDLine]);
 
 
  if(CarAngle>=0) 
  LCD_Show_Number (0,4,(int)     CarAngle); 
  else
  {
     LCD_Show_Number (0,4,(int)(absf(CarAngle)));
     LCD_write_char(0, 4,'-');  LCD_write_char(0, 4,'-'); LCD_write_char(0, 4,'-'); LCD_write_char(0, 4,'-'); LCD_write_char(0, 4,'-');
  }
  
  if(key_count==1)   {LCD_write_char(0, 0,'+'); LCD_write_char(0, 0,'+');LCD_write_char(0, 0,'+'); LCD_write_char(0, 0,'+'); }
  if(key_count==2)   {LCD_write_char(0, 2,'+'); LCD_write_char(0, 2,'+');LCD_write_char(0, 2,'+'); LCD_write_char(0, 2,'+'); }     
  if(key_count==3)   {LCD_write_char(48, 0,'+');LCD_write_char(48, 0,'+');LCD_write_char(48, 0,'+');LCD_write_char(48, 0,'+');  }
  if(key_count==4)   {LCD_write_char(48, 1,'+'); LCD_write_char(48, 1,'+');LCD_write_char(48, 1,'+'); LCD_write_char(48, 1,'+');}  
  if(key_count==5)   {LCD_write_char(48, 2,'+'); LCD_write_char(48, 2,'+');LCD_write_char(48, 2,'+'); LCD_write_char(48, 2,'+');}  
  if(key_count==6)   {LCD_write_char(96, 0,'+'); LCD_write_char(96, 0,'+');LCD_write_char(96, 0,'+'); LCD_write_char(96, 0,'+');}       
  if(key_count==7)   {LCD_write_char(96, 2,'+'); LCD_write_char(96, 2,'+');LCD_write_char(96, 2,'+'); LCD_write_char(96, 2,'+');}

 
  if(bell_flat==1)
  bell(200);

   } 
}
